/**
 * <p>Title: ServiceZMCM63.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 余虎
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-8 下午04:42:32  余虎  Create
 *</pre>
 */
package com.baosight.sczx.zm.cm.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.common.zm.cInterface.User;
import com.baosight.sczx.common.zm.cInterface.cs.InitialData;
import com.baosight.sczx.zm.cm.domain.ZMCMStockPlan;

/**采购计划---月采购计划管理
 * <p>Title: ServiceZMCM63.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 余虎
 * @version 1.0
 * <pre>Histroy:
 *          2011-6-8 下午04:42:32  余虎  Create
 *</pre>
 */
public class ServiceZMCMD6 extends ServiceEPBase {


	/**初始化数据
	 * <p>Function: initLoad</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM63</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-8下午04:43:23 余虎
	 * </p>
	 *
	*/
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cs.units"));//构造计量单位下拉框
		outInfo.addBlock(User.getInstance().getConstructionStaff("cmes.cm.empName", "empCode", "empName", false));
		outInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.cm.department", "orgCode", "orgName", false));
		return outInfo;
	}

	

	/**查询
	 * <p>Function: query</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM63</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-8下午04:43:23 余虎
	 * </p>
	 *
	*/
	@Override
	public EiInfo query(EiInfo inInfo) {
		String subStr = inInfo.getString("fdParentId");
		String temp = new String(inInfo.getString("fdParentId"));
		int tempLenght = temp.length();
		String year = (subStr).substring(0,4);//树节点ID
		String month= (subStr).substring(4,tempLenght);
		StaticTools.setQueryParameters(inInfo, "fdYear", year, true);//添加查询条件
		StaticTools.setQueryParameters(inInfo, "fdMonth", month, true);//添加查询条件
		//StaticTools.setQueryParameters(inInfo, "fdApplicationDeparment",UserSession.getInSessionProperty("orgCode").toString(),true);//当前部门
		EiInfo outInfo = super.query(inInfo, "ZMCMStockPlan.query",new ZMCMStockPlan());
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cs.units"));
		outInfo.addBlock(User.getInstance().getConstructionStaff("cmes.cm.empName", "empCode", "empName", false));
		outInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.cm.department", "orgCode", "orgName", false));
		return outInfo;
	}
	/**
	 * <p>Function: insert</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM63</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-8下午04:43:23 余虎
	 * </p>
	 *
	*/
	@Override
	public EiInfo insert(EiInfo inInfo) {
		return super.insert(inInfo);
	}
	/**
	 * <p>Function: update</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM63</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-8下午04:43:23 余虎
	 * </p>
	 *
	*/
	@Override
	public EiInfo update(EiInfo inInfo) {
		return super.update(inInfo);
	}

	/**删除
	 * <p>Function: delete</p>
	 * <p>Description: </p>
	 * <p>return value: ServiceZMCM63</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-6-8下午04:43:23 余虎
	 * </p>
	 *
	*/
	@Override
	public EiInfo delete(EiInfo inInfo) {
		String keyId =inInfo.getBlock("result").getCellStr(0, "fdKeyId");
		Map<String, String> param = new HashMap<String, String>();
		param.put("fdStockPlanId", keyId);
		List<?> list = dao.query("ZMCMStockPlanDetail.query", param);
		
		if(list.size()>0){
			inInfo.setStatus(-1);
			inInfo.setMsg("该计划下存在明细计划，不能删除！");
			return inInfo;
		}
		else{
			EiInfo _temp = super.delete(inInfo, "ZMCMStockPlan.delete");
			EiInfo outInfo = this.query(inInfo);
			outInfo.setMsg(_temp.getMsg());
			outInfo.setDetailMsg(_temp.getDetailMsg());
			return outInfo;
		}
	}

	/**
	 * 生效
	 * <p>Function: report</p>
	 * <p>Description: </p>
	 * <p>return value:EiInfo</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-9-16下午11:07:27 张志芳
	 * </p>
	 *
	 */
	public EiInfo report(EiInfo inInfo)
	{
		EiInfo _temp = super.update(inInfo, "ZMCMStockPlan.report");
        EiInfo outInfo = this.query(inInfo);
        outInfo.setMsg(_temp.getMsg());
        outInfo.setDetailMsg(_temp.getDetailMsg());
		return outInfo;
	}
}
